<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis 持久化方案深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* 首字下沉效果 */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #4f46e5;
            font-family: 'Noto Serif SC', serif;
        }
        
        /* 卡片悬停效果 */
        .feature-card {
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.9);
        }
        
        .feature-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }
        
        /* 渐变文字效果 */
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        /* 动画效果 */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out forwards;
        }
        
        /* 自定义滚动条 */
        ::-webkit-scrollbar {
            width: 10px;
        }
        
        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        
        ::-webkit-scrollbar-thumb {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 5px;
        }
        
        /* 代码块样式 */
        .code-inline {
            background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
            padding: 0.2rem 0.5rem;
            border-radius: 0.375rem;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 0.875rem;
            color: #4f46e5;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        }
        
        /* 列表样式优化 */
        .custom-list li {
            position: relative;
            padding-left: 2rem;
            margin-bottom: 1rem;
        }
        
        .custom-list li::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0.5rem;
            width: 0.5rem;
            height: 0.5rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
        }
        
        /* Mermaid 图表样式 */
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body>
    <!-- Hero 区域 -->
    <section class="relative overflow-hidden">
        <div class="absolute inset-0 bg-gradient-to-br from-purple-600 via-indigo-600 to-blue-600 opacity-90"></div>
        <div class="relative z-10 container mx-auto px-6 py-24">
            <div class="text-center text-white animate-fadeInUp">
                <h1 class="text-5xl md:text-7xl font-bold mb-6">
                    Redis <span class="gradient-text bg-gradient-to-r from-yellow-300 to-pink-300">持久化方案</span>
                </h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">深度解析 RDB、AOF 与混合持久化的选择之道</p>
                <div class="flex justify-center space-x-4">
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full backdrop-blur-sm">
                        <i class="fas fa-database mr-2"></i> 数据安全
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full backdrop-blur-sm">
                        <i class="fas fa-bolt mr-2"></i> 高性能
                    </span>
                    <span class="inline-flex items-center px-4 py-2 bg-white bg-opacity-20 rounded-full backdrop-blur-sm">
                        <i class="fas fa-shield-alt mr-2"></i> 可靠性
                    </span>
                </div>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="white" fill-opacity="0.1"/>
            </svg>
        </div>
    </section>

    <!-- 引言部分 -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-4xl mx-auto">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    在选择 Redis 持久化方案时，了解 RDB（快照）、AOF（追加文件）和混合持久化的特点、优缺点对于做出正确的选择至关重要。以下是对这三种持久化方案的详细比较，帮助你决定哪一个最适合你的应用场景。
                </p>
            </div>
        </div>
    </section>

    <!-- 数据可视化：持久化方案对比 -->
    <section class="container mx-auto px-6 py-8">
        <div class="max-w-6xl mx-auto">
            <h2 class="text-3xl font-bold text-center mb-12 gradient-text">持久化方案架构图</h2>
            <div class="bg-white rounded-2xl shadow-xl p-8">
                <div class="mermaid">
                    graph TB
                        A[Redis 持久化方案] --> B[RDB 快照持久化]
                        A --> C[AOF 日志持久化]
                        A --> D[混合持久化]
                        
                        B --> B1[定期快照]
                        B --> B2[二进制存储]
                        B --> B3[快速恢复]
                        
                        C --> C1[命令日志]
                        C --> C2[实时记录]
                        C --> C3[高持久性]
                        
                        D --> D1[RDB + AOF]
                        D --> D2[快速恢复]
                        D --> D3[数据安全]
                        
                        style A fill:#667eea,stroke:#4f46e5,stroke-width:3px,color:#fff
                        style B fill:#fbbf24,stroke:#f59e0b,stroke-width:2px
                        style C fill:#34d399,stroke:#10b981,stroke-width:2px
                        style D fill:#f472b6,stroke:#ec4899,stroke-width:2px
                </div>
            </div>
        </div>
    </section>

    <!-- RDB 持久化详解 -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-6xl mx-auto">
            <div class="mb-16">
                <div class="flex items-center mb-8">
                    <div class="w-16 h-16 bg-gradient-to-br from-yellow-400 to-orange-500 rounded-2xl flex items-center justify-center text-white text-2xl font-bold shadow-lg">
                        <i class="fas fa-camera"></i>
                    </div>
                    <h2 class="text-4xl font-bold ml-6">RDB 快照持久化</h2>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="feature-card rounded-2xl p-8 shadow-lg">
                        <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                            <i class="fas fa-cog text-yellow-500 mr-3"></i>核心特点
                        </h3>
                        <ul class="custom-list text-gray-700">
                            <li><strong>数据快照：</strong>RDB 持久化是通过定期创建数据库的时间点快照来保存数据。快照以二进制形式存储在 RDB 文件中。</li>
                            <li><strong>创建方式：</strong>可以通过配置的时间间隔和数据修改次数来触发 RDB 快照的创建（例如，每隔 5 分钟或每 1000 次修改）。</li>
                        </ul>
                    </div>
                    
                    <div class="grid gap-4">
                        <div class="feature-card rounded-xl p-6 shadow-lg bg-gradient-to-br from-green-50 to-emerald-50">
                            <h4 class="text-xl font-semibold mb-3 text-green-800">
                                <i class="fas fa-check-circle mr-2"></i>优点
                            </h4>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-tachometer-alt text-green-600 mr-2"></i><strong>性能开销小：</strong>RDB 在生成快照时不会对 Redis 性能造成显著影响，因为它在后台进程中进行。</li>
                                <li><i class="fas fa-rocket text-green-600 mr-2"></i><strong>恢复速度快：</strong>RDB 文件通常较小，恢复速度较快，适合大规模数据恢复。</li>
                                <li><i class="fas fa-archive text-green-600 mr-2"></i><strong>备份方便：</strong>RDB 文件易于备份和迁移。</li>
                            </ul>
                        </div>
                        
                        <div class="feature-card rounded-xl p-6 shadow-lg bg-gradient-to-br from-red-50 to-pink-50">
                            <h4 class="text-xl font-semibold mb-3 text-red-800">
                                <i class="fas fa-exclamation-triangle mr-2"></i>缺点
                            </h4>
                            <ul class="space-y-2 text-gray-700">
                                <li><i class="fas fa-database text-red-600 mr-2"></i><strong>数据丢失风险：</strong>由于 RDB 是定期创建快照，最后一次快照后至系统崩溃之间的数据修改会丢失。</li>
                                <li><i class="fas fa-pause-circle text-red-600 mr-2"></i><strong>写操作阻塞：</strong>在创建快照期间，可能会有短暂的写操作阻塞。</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- AOF 持久化详解 -->
    <section class="container mx-auto px-6 py-16 bg-gray-50">
        <div class="max-w-6xl mx-auto">
            <div class="mb-16">
                <div class="flex items-center mb-8">
                    <div class="w-16 h-16 bg-gradient-to-br from-green-400 to-teal-500 rounded-2xl flex items-center justify-center text-white text-2xl font-bold shadow-lg">
                        <i class="fas fa-file-alt"></i>
                    </div>
                    <h2 class="text-4xl font-bold ml-6">AOF 追加文件持久化</h2>
                </div>
                
                <div class="grid md:grid-cols-2 gap-8">
                    <div class="feature-card rounded-2xl p-8 shadow-lg">
                        <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                            <i class="fas fa-list-ul text-green-500 mr-3"></i>核心特点
                        </h3>
                        <ul class="custom-list text-gray-700">
                            <li><strong>命令日志：</strong>AOF 记录 Redis 执行的所有写操作命令，并追加到 AOF 文件中。每次写操作都会被记录，保证了数据